<script>
$(function(){
    	$("#year_semester, #class_grade").change(function(){
    		$("#act").attr('value','');
    	    $("#selectForm").submit();
        });
    	$("#checkAll").click(function(){
            $.each($("INPUT[@name='student_id[]'][type='checkbox']"),function(){
                $(this).attr('checked', !$(this).is(':checked'));
            });
       });
        $("#downloadBtn").click(function(){
            if ($("#select-report").val() =='') {
                alert('<?php echo $this->translate("choose a template to print")?>');
                return false;
            }
            if ($("INPUT[@name='student_id[]'][type='checkbox']:checked").length ==0) {
                alert("<?php echo $this->translate('choose more than one student')?>");
                return false;
            }
            //$("#downloadBtn").attr('disabled','true');
            $("#act").attr('value','download');
            $("#selectForm").submit();
        });

});
</script>
<style>
.selected {border:#00f solid thin}
</style>
<?php $conditionArray = Student_Model_Student::getStudentConditionArray()?>

<form action="" method="post" id="selectForm">
<div id="select-div" >
<select name="year_semester" id="year_semester">
<?php echo $this->YearSemesterOptions($this->year_semester ,array('order' => 'year DESC, semester'))?>
</select>
<select name="class_grade" id="class_grade">
<option value=""><?php echo  $this->translate('select ..')?></option>
<?php echo $this->ClassNameOptions($this->year_semester, $this->class_grade)?>
</select>
<?php if ($this->data):?>
<input type="button"  id="checkAll" value="<?php echo $this->translate('select all / unselect')?>" />
<?php endif?>
</div>
<?php if ($this->data):?>
<div class="ui-widget-content ui-corner-all" style="margin:10px 5px; padding:5px;">
<table>
<thead>
</thead>
<tbody>
<?php $i=0;?>
<?php foreach($this->data as $row) :?>
<?php if ($i++ % 4 == 0):?><tr><?php endif?>
<td>
<input type="checkbox" name="student_id[]"  id="sel-<?php echo $row['sn']?>" value="<?php echo $row['sn']?>" />
<label for="sel-<?php echo $row['sn']?>"><?php echo sprintf("%02d %s",$row['number'], $row['name'])?></label>
<?php if ($row['study_condition']):?>
<span style="color:#f99">(<?php echo $conditionArray[$row['study_condition']]?>)</span>
<?php endif?>
</td>
<?php if ($i %4 == 0):?></tr><?php endif?>
<?php endforeach?>
</tbody>
</table>
</div>

<select id="select-report" name="report_kind">
<option value=""><?php echo $this->translate('select a template to print')?></option>
<?php foreach($this->reports as $id=>$name):?>
<option value="<?php echo $id?>"><?php echo $name?></option>
<?php endforeach?>
</select>
<input type="button"  id="downloadBtn" name="act" value="<?php echo $this->translate('download report')?>" />
<input type="hidden" id="act" name="act" />
<?php endif?>
</form>
